package tw.miku.protocol.codec.gold;

import java.nio.charset.CharacterCodingException;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

import org.apache.mina.core.buffer.IoBuffer;

import tw.miku.constants.ProtocalConstants;
import tw.miku.model.ICard;
import tw.miku.model.gold.GoldGameUser;
import tw.miku.protocol.codec.AbstractResponseMessagePack;
import tw.miku.util.BufferUtility;

public class GoldGameStartResponsePack extends AbstractResponseMessagePack
{
	public int heroType;

	public long turn;

	public ArrayList<ICard> cards;

	public IoBuffer users;

	public GoldGameStartResponsePack()
	{

	}

	@Override
	public short getTag()
	{
		return ProtocalConstants.GOLD_GAME_START;
	}

	@Override
	public IoBuffer encode() throws CharacterCodingException
	{
		IoBuffer buf = IoBuffer.allocate(100).setAutoExpand(true);

		buf.position(4);
		buf.putShort(getTag());
		buf.putShort((short) 0);
		buf.put((byte) heroType);
		buf.put(users);
		buf.putUnsignedInt(turn);
		BufferUtility.writeArray(buf, cards);

		buf.flip();
		buf.putUnsignedInt(buf.limit() - 4);
		buf.position(0);
		return buf;
	}
}
